package com.cqu.hhx.driver.service.impl;

import com.cqu.hhx.driver.entity.Customer;
import com.cqu.hhx.driver.entity.Driver;
import com.cqu.hhx.driver.mapper.CustomerMapper;
import com.cqu.hhx.driver.mapper.DriverMapper;
import com.cqu.hhx.driver.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author DJ
 * @create 2020-05-24 22:09
 */
@Service
public class RegisterServiceImpl implements RegisterService {
    @Autowired
    private CustomerMapper customerMapper;
    @Autowired
    private DriverMapper driverMapper;

    /**
     * 添加乘客信息
     * @param customer
     * @return 0,1,2
     */
    @Override
    public Integer addCustomer(Customer customer) {
        try {
            Customer item = customerMapper.getCustomerInfo(customer.getAccount());
            if (item!=null){
                return 1;
            }else{
                customerMapper.addCustomer(customer);
                return 0;
            }
        }catch (Exception e){
            e.printStackTrace();
            return 2;
        }
    }

    /**
     * 添加司机信息
     * @param driver
     * @return 0,1,2
     */
    @Override
    public Integer addDriver(Driver driver) {
        try {
            Driver item=driverMapper.getDriverInfo(driver.getAccount());
            if(item==null) {
                driverMapper.addDriver(driver);
                return 0;
            }else{
                return 1;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return 2;
        }
    }
}
